package mapReduce.demo04_IOFormat.outputFormat;

import mapReduce.util.JobSubmit;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mapreduce.Reducer;
import org.apache.hadoop.mapreduce.lib.output.SequenceFileOutputFormat;

import java.io.IOException;

public class TextInSequenceOutApp {

    public static class TISOMapper extends Mapper<LongWritable, Text,Text, IntWritable>{

        Text outKey = new Text();
        IntWritable outValue = new IntWritable();

        @Override
        protected void map(LongWritable key, Text value, Mapper<LongWritable, Text, Text, IntWritable>.Context context) throws IOException, InterruptedException {

            String line = value.toString();
            String[] fields = line.split(",");

            outKey.set(fields[0]);
            outValue.set(Integer.parseInt(fields[1]));

            context.write(outKey,outValue);

        }
    }

    public static class TISOReducer extends Reducer<Text,IntWritable,Text,IntWritable>{
        @Override
        protected void reduce(Text key, Iterable<IntWritable> values, Reducer<Text, IntWritable, Text, IntWritable>.Context context) throws IOException, InterruptedException {
            super.reduce(key, values, context);
        }
    }

    public static void main(String[] args) {
        JobSubmit.submitBaseJob(TextInSequenceOutApp.class,args,SequenceFileOutputFormat.class);
    }

}
